<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />

  <title>Class: Mongoid::Autoinc::Incrementor</title>

  <link rel="stylesheet" href="../../rdoc.css" type="text/css" media="screen" />

  <script src="../../js/jquery.js" type="text/javascript" charset="utf-8"></script>
  <script src="../../js/thickbox-compressed.js" type="text/javascript" charset="utf-8"></script>
  <script src="../../js/quicksearch.js" type="text/javascript" charset="utf-8"></script>
  <script src="../../js/darkfish.js" type="text/javascript" charset="utf-8"></script>

</head>
<body id="top" class="class">

  <div id="metadata">
    <div id="home-metadata">
      <div id="home-section" class="section">
        <h3 class="section-header">
          <a href="../../index.html">Home</a>
          <a href="../../index.html#classes">Classes</a>
          <a href="../../index.html#methods">Methods</a>
        </h3>
      </div>
    </div>

    <div id="file-metadata">
      <div id="file-list-section" class="section">
        <h3 class="section-header">In Files</h3>
        <div class="section-body">
          <ul>
          
            <li><a href="../../lib/autoinc/incrementor_rb.html?TB_iframe=true&amp;height=550&amp;width=785"
              class="thickbox" title="lib/autoinc/incrementor.rb">lib/autoinc/incrementor.rb</a></li>
          
          </ul>
        </div>
      </div>

      
    </div>

    <div id="class-metadata">
      
      <!-- Parent Class -->
      <div id="parent-class-section" class="section">
        <h3 class="section-header">Parent</h3>
        
        <p class="link">Object</p>
        
      </div>
      

      

      

      
      <!-- Method Quickref -->
      <div id="method-list-section" class="section">
        <h3 class="section-header">Methods</h3>
        <ul class="link-list">
          
          <li><a href="#method-c-new">::new</a></li>
          
          <li><a href="#method-i-inc">#inc</a></li>
          
          <li><a href="#method-i-key">#key</a></li>
          
        </ul>
      </div>
      

      
    </div>

    <div id="project-metadata">
      
      

      <div id="classindex-section" class="section project-section">
        <h3 class="section-header">Class/Module Index
          <span class="search-toggle"><img src="../../images/find.png"
            height="16" width="16" alt="[+]"
            title="show/hide quicksearch" /></span></h3>
        <form action="#" method="get" accept-charset="utf-8" class="initially-hidden">
        <fieldset>
          <legend>Quicksearch</legend>
          <input type="text" name="quicksearch" value=""
            class="quicksearch-field" />
        </fieldset>
        </form>

        <ul class="link-list">
        
          <li><a href="../../Mongoid.html">Mongoid</a></li>
        
          <li><a href="../../Mongoid/Autoinc.html">Mongoid::Autoinc</a></li>
        
          <li><a href="../../Mongoid/Autoinc/ClassMethods.html">Mongoid::Autoinc::ClassMethods</a></li>
        
          <li><a href="../../Mongoid/Autoinc/Incrementor.html">Mongoid::Autoinc::Incrementor</a></li>
        
        </ul>
        <div id="no-class-search-results" style="display: none;">No matching classes.</div>
      </div>

      
    </div>
  </div>

  <div id="documentation">
    <h1 class="class">Mongoid::Autoinc::Incrementor</h1>

    <div id="description" class="description">
      
    </div><!-- description -->

    
    
    
    <div id="5Buntitled-5D" class="documentation-section">
      

      

      

      
      <!-- Attributes -->
      <div id="attribute-method-details" class="method-section section">
        <h3 class="section-header">Attributes</h3>

        
        <div id="collection-attribute-method" class="method-detail">
          <a name="collection"></a>
          
          <a name="collection="></a>
          
          <div class="method-heading attribute-method-heading">
            <span class="method-name">collection</span><span
              class="attribute-access-type">[RW]</span>
          </div>

          <div class="method-description">
          
          
          
          </div>
        </div>
        
        <div id="field_name-attribute-method" class="method-detail">
          <a name="field_name"></a>
          
          <a name="field_name="></a>
          
          <div class="method-heading attribute-method-heading">
            <span class="method-name">field_name</span><span
              class="attribute-access-type">[RW]</span>
          </div>

          <div class="method-description">
          
          
          
          </div>
        </div>
        
        <div id="model_name-attribute-method" class="method-detail">
          <a name="model_name"></a>
          
          <a name="model_name="></a>
          
          <div class="method-heading attribute-method-heading">
            <span class="method-name">model_name</span><span
              class="attribute-access-type">[RW]</span>
          </div>

          <div class="method-description">
          
          
          
          </div>
        </div>
        
        <div id="scope_key-attribute-method" class="method-detail">
          <a name="scope_key"></a>
          
          <a name="scope_key="></a>
          
          <div class="method-heading attribute-method-heading">
            <span class="method-name">scope_key</span><span
              class="attribute-access-type">[RW]</span>
          </div>

          <div class="method-description">
          
          
          
          </div>
        </div>
        
        <div id="seed-attribute-method" class="method-detail">
          <a name="seed"></a>
          
          <a name="seed="></a>
          
          <div class="method-heading attribute-method-heading">
            <span class="method-name">seed</span><span
              class="attribute-access-type">[RW]</span>
          </div>

          <div class="method-description">
          
          
          
          </div>
        </div>
        
        <div id="step-attribute-method" class="method-detail">
          <a name="step"></a>
          
          <a name="step="></a>
          
          <div class="method-heading attribute-method-heading">
            <span class="method-name">step</span><span
              class="attribute-access-type">[RW]</span>
          </div>

          <div class="method-description">
          
          
          
          </div>
        </div>
        
      </div><!-- attribute-method-details -->
      

      <!-- Methods -->
      
      <div id="public-class-method-details" class="method-section section">
        <h3 class="section-header">Public Class Methods</h3>

      
        <div id="new-method" class="method-detail ">
          <a name="method-c-new"></a>

          
          <div class="method-heading">
            <span class="method-name">new</span><span
              class="method-args">(model_name, field_name, options={})</span>
            <span class="method-click-advice">click to toggle source</span>
          </div>
          

          <div class="method-description">
            
            
            

            
            <div class="method-source-code" id="new-source">
<pre>
<span class="ruby-comment"># File lib/autoinc/incrementor.rb, line 8</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">model_name</span>, <span class="ruby-identifier">field_name</span>, <span class="ruby-identifier">options</span>={})
  <span class="ruby-keyword">self</span>.<span class="ruby-identifier">model_name</span> = <span class="ruby-identifier">model_name</span>.<span class="ruby-identifier">to_s</span>
  <span class="ruby-keyword">self</span>.<span class="ruby-identifier">field_name</span> = <span class="ruby-identifier">field_name</span>.<span class="ruby-identifier">to_s</span>
  <span class="ruby-keyword">self</span>.<span class="ruby-identifier">scope_key</span> = <span class="ruby-identifier">options</span>[<span class="ruby-value">:scope</span>]
  <span class="ruby-keyword">self</span>.<span class="ruby-identifier">step</span> = <span class="ruby-identifier">options</span>[<span class="ruby-value">:step</span>] <span class="ruby-operator">||</span> <span class="ruby-value">1</span>
  <span class="ruby-keyword">self</span>.<span class="ruby-identifier">seed</span> = <span class="ruby-identifier">options</span>[<span class="ruby-value">:seed</span>]
  <span class="ruby-keyword">self</span>.<span class="ruby-identifier">collection</span> = <span class="ruby-operator">::</span><span class="ruby-constant">Mongoid</span>.<span class="ruby-identifier">default_session</span>[<span class="ruby-string">'auto_increment_counters'</span>]
  <span class="ruby-identifier">create</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">seed</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-operator">!</span><span class="ruby-identifier">exists?</span>
<span class="ruby-keyword">end</span></pre>
            </div><!-- new-source -->
            
          </div>

          

          
        </div><!-- new-method -->

      
      </div><!-- public-class-method-details -->
    
      <div id="public-instance-method-details" class="method-section section">
        <h3 class="section-header">Public Instance Methods</h3>

      
        <div id="inc-method" class="method-detail ">
          <a name="method-i-inc"></a>

          
          <div class="method-heading">
            <span class="method-name">inc</span><span
              class="method-args">()</span>
            <span class="method-click-advice">click to toggle source</span>
          </div>
          

          <div class="method-description">
            
            
            

            
            <div class="method-source-code" id="inc-source">
<pre>
<span class="ruby-comment"># File lib/autoinc/incrementor.rb, line 25</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">inc</span>
  <span class="ruby-identifier">collection</span>.<span class="ruby-identifier">find</span>(
    <span class="ruby-string">'_id'</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">key</span>
  ).<span class="ruby-identifier">modify</span>(
    {<span class="ruby-string">'$inc'</span> =<span class="ruby-operator">&gt;</span> { <span class="ruby-string">'c'</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">step</span> }},
    <span class="ruby-value">:new</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword">true</span>, <span class="ruby-value">:upsert</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword">true</span>
  )[<span class="ruby-string">'c'</span>]
<span class="ruby-keyword">end</span></pre>
            </div><!-- inc-source -->
            
          </div>

          

          
        </div><!-- inc-method -->

      
        <div id="key-method" class="method-detail ">
          <a name="method-i-key"></a>

          
          <div class="method-heading">
            <span class="method-name">key</span><span
              class="method-args">()</span>
            <span class="method-click-advice">click to toggle source</span>
          </div>
          

          <div class="method-description">
            
            
            

            
            <div class="method-source-code" id="key-source">
<pre>
<span class="ruby-comment"># File lib/autoinc/incrementor.rb, line 18</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">key</span>
  <span class="ruby-string">&quot;&quot;</span>.<span class="ruby-identifier">tap</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">str</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">str</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-node">&quot;#{model_name.underscore}_#{field_name}&quot;</span>
    <span class="ruby-identifier">str</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-node">&quot;_#{scope_key}&quot;</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">scope_key</span>.<span class="ruby-identifier">blank?</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
            </div><!-- key-source -->
            
          </div>

          

          
        </div><!-- key-method -->

      
      </div><!-- public-instance-method-details -->
    
    </div><!-- 5Buntitled-5D -->
  

  </div><!-- documentation -->

  <div id="validator-badges">
    <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
    <p><small>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish
      Rdoc Generator</a> 2</small>.</p>
  </div>

</body>
</html>

